package com.example.com.hupu.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.com.hupu.R;
import com.example.com.hupu.bean.VideoItem;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.jzvd.Jzvd;

/**
 * 新闻Adapter
 */
public class VideoAdapter extends RecyclerView.Adapter<VideoAdapter.ViewHolder> {

    public List<VideoItem> mResult;

    public VideoAdapter(List<VideoItem> result) {
        this.mResult = result;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_news_list_videos, parent, false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull final ViewHolder holder, int position) {
        final VideoItem videoItem = mResult.get(position);
        holder.tvVideoTitle.setText(videoItem.title);
        holder.tvVideoDate.setText(videoItem.publishTime);
        holder.tvVideoDuration.setText(videoItem.duration);
        Glide.with(holder.ivGotoWeb).load(videoItem.imgurl).into(holder.ivGotoWeb);

        holder.jcNewsListPlayer.setUp(videoItem.videoUrl, videoItem.title, Jzvd.SCREEN_WINDOW_NORMAL);
    }

    @Override
    public int getItemCount() {
        return mResult == null ? 0 : mResult.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.jc_news_list_player)
        public cn.jzvd.JzvdStd jcNewsListPlayer;
        @BindView(R.id.tv_video_title)
        public TextView tvVideoTitle;
        @BindView(R.id.tv_video_duration)
        public TextView tvVideoDuration;
        @BindView(R.id.iv_goto_web)
        public ImageView ivGotoWeb;
        @BindView(R.id.tv_video_date)
        public TextView tvVideoDate;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}